package com.axjy.service.impl;

import com.axjy.mapper.UserMapper;
import com.axjy.pojo.User;
import com.axjy.service.UserService;
import com.axjy.vo.UserDto;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

@Service("userService")
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;


    public User searchUserByUserCode(String userCode){
        QueryWrapper<User> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("user_code",userCode);
        User user= userMapper.selectOne(queryWrapper);
        return user;
    }




    @Override
    public Page<User> queryAll(int page, int limit, UserDto userDto) {
        Page<User> userPage=new Page<>();
        userPage.setCurrent(page);
        userPage.setSize(limit);
        userPage=userMapper.findAll(userPage,userDto);
        return userPage;
    }

    @Override
    public void updateAttach(User user) {
        userMapper.updateAttach(user.getId(),user.getAttachPath(),user.getAttachDescr());
    }

    @Override
    public void addUser(User user) {

        userMapper.insert(user);

    }

    @Override
    public void updateUser(User user) {
        userMapper.updateById(user);
    }

    @Override
    public void batchDel(Integer[] ids) {
        userMapper.deleteBatchIds(Arrays.asList(ids));
    }

    @Override
    public void deleteById(Integer id) {
        userMapper.deleteById(id);
    }
}
